<template>
  <div class="dashboard-container">
    <div class="app-container">
      <!-- 新增区域 -->
      <el-button type="primary" icon="el-icon-plus">新增企业</el-button>
      <el-card class="filter">
        <!-- 搜索区域 -->
        <el-form label-width="80px" :model="queryForm" ref="queryFormRef">
          <el-row>
            <el-col :span="6">
              <el-form-item label="标签名称" prop="tags">
                <el-input v-model="queryForm.tags"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="企业简称" prop="shortName">
                <el-input v-model="queryForm.shortName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="企业状态" prop="state">
                <el-select v-model="queryForm.state" placeholder="请选择">
                  <el-option
                    v-for="item in stateList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-button type="info" @click="resetQueryForm">清除</el-button>
              <el-button type="primary">搜索</el-button>
            </el-col>
          </el-row>
        </el-form>
        <!-- 数据列表 -->
        <el-table :data="dataList" border stripe>
          <el-table-column type="index"></el-table-column>
          <el-table-column prop="number" label="编号"></el-table-column>
          <el-table-column prop="shortName" label="企业简介"></el-table-column>
          <el-table-column prop="tags" label="标签"></el-table-column>
          <el-table-column prop="creatorID" label="创建者"></el-table-column>
          <el-table-column prop="addDate" label="创建日期"></el-table-column>
          <el-table-column prop="remarks" label="备注"></el-table-column>
          <el-table-column prop="state" label="状态">
            <template slot-scope="scope">
              {{scope.row.state?'启用':'禁用'}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="250px">
            <template slot-scope="scope">
              <el-button type="primary" size="mini">修改</el-button>
              <el-button type="primary" size="mini">禁用</el-button>
              <el-button type="danger" size="mini" @click="del(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页区域 -->
        <div class="page-area">
          <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.page"
          :page-sizes="[2,5,10,20]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
          </el-pagination>
        </div>
      </el-card>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      queryForm : {
        tags:'',
        shortName:'',
        state:''
      },
      stateList:[
        {label:'启用',value:1},
        {label:'禁用',value:0}
      ],
      total:0,
      dataList:[],
      queryInfo:{
        page:1,
        pagesize:5,
        tags:'',
        province:'',
        city:'',
        shortName:'',
        state:''
      }
    };
  },
  created(){
    this.getList()  
  },
  methods:{
    resetQueryForm(){
      this.$refs.queryFormRef.resetFields()
    },
    async getList(){
      const {data:res} = await this.$http.get('companys',{params:{page:this.queryInfo.page,pagesize:this.queryInfo.pagesize}})
      this.dataList = res.items
      this.total = res.counts 
    },
    handleSizeChange(pagesize){
      this.queryInfo.pagesize = pagesize 
      this.getList()
    },
    handleCurrentChange(page){
      this.queryInfo.page = page 
      this.getList()
    },
    async del(id){
      const {data:res} = await this.$http.delete('companys/'+id)
      if(res.success){
        this.getList()
      }
    }
  }
}
</script>
<style lang='scss' scoped>
.filter{
  margin:15px 0;
  .el-col{
    .el-form-item--medium{
      margin:0;
    }
  }
}
.page-area{
  display: flex;
  justify-content: center;
  margin-top: 15px;
}
</style>